package cn.cjj.gulimall.product.web;

import cn.cjj.gulimall.product.entity.CategoryEntity;
import cn.cjj.gulimall.product.service.CategoryService;
import cn.cjj.gulimall.product.vo.Catalog2Vo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

/**
 * @author CuiJunJie
 * @create 2021/6/22-19:32
 */

@Controller
public class IndexController {

    @Autowired
    CategoryService categoryService;


    @GetMapping({"/", "index.html"})
    public String indexPage(Model model) {

        List<CategoryEntity> categorys = categoryService.getLevel1Categorys();

        model.addAttribute("categorys", categorys);

        return "index";
    }

    @ResponseBody
    @GetMapping("/index/catalog.json")
    public Map<String, List<Catalog2Vo>> getCatelog2Json() {
        System.out.println("/index/catelog.json");
        Map<String, List<Catalog2Vo>> catelog2Json = categoryService.getCatelog2Json();

        return catelog2Json;
    }
}
